import pygame
from pygame.sprite import Sprite


class Bullet(Sprite):
    """
    子弹类
    """
    def __init__(self, XiaoTie):
        super(Bullet, self).__init__()
        self.image = pygame.image.load("resources/images/shoot/bullet.png")
        self.air = XiaoTie.flag
        x, y, self.width, self.height = self.image.get_rect()
        self.rect = pygame.Rect(XiaoTie.pos_x, XiaoTie.pos_y, self.width, self.height)
        self.y = XiaoTie.pos_y
        self.x = XiaoTie.pos_x
        self.speed_factor = 20

    def run(self):
        """
        子弹移动
        """
        x, y = 0, 0
        # print(self.air)
        if self.air == 1:
            # print("111")
            self.y += self.speed_factor
            y += self.speed_factor
        elif self.air == 2:
            # print("222")
            self.y -= self.speed_factor
            y -= self.speed_factor
        elif self.air == 3:
            self.x -= self.speed_factor
            x -= self.speed_factor
        elif self.air == 4:
            self.x += self.speed_factor
            x += self.speed_factor
        self.rect = self.rect.move(x, y)

    def draw_bullet(self, surface: pygame.surface, x: int, y: int):
        """
        在屏幕上绘制子弹
        """
        surface.blit(self.image, (self.x - x + 13, self.y - y + 35))
        pygame.draw.rect(surface, pygame.Color(255, 255, 0), (self.x - x + 13, self.y - y + 35, self.width, self.height), True)
